//logs.js
 
Page({
 /**
   * 页面的初始数据
   */
  data: {
      menuList: [
      {
        name: '开放接口',
        expand: true,
        List: [{
          zhName: '微信登录',
          enName: 'login',
          url: '../practice/login/login'
        }, {
          zhName: '获取用户信息',
          enName: 'getUserInfo',
          url: '../practice/get-user-info/get-user-info'
        }, {
          zhName: '发起支付',
          enName: 'requestPayment',
          url: '../practice/request-payment/request-payment'
        }]
      }, 
      {
        name: '界面',
        expand: true,
        List: [{
          zhName: '设置界面标题',
          enName: 'setNavigationBarTitle',
          url: '../practice/set-navigation-bar-title/set-navigation-bar-title'
        }, {
          zhName: '标题栏加载动画',
          enName: 'navigationBarLoading',
          url: '../practice/navigation-bar-loading/navigation-bar-loading'
        }, {
          zhName: '页面跳转',
          enName: 'navigateTo, navigateBack, redirectTo',
          url: '../practice/navigator/navigator'
        }, {
          zhName: '下拉刷新',
          enName: 'pullDownRefresh',
          url: '../practice/pull-down-refresh/pull-down-refresh'
        }, {
          zhName: '创建动画',
          enName: 'createAnimation',
          url: '../practice/animation/animation'
        }, {
          zhName: '创建绘画',
          enName: 'createContext',
          url: '../practice/canvas/canvas'
        }]
      }, 
      {
        name: '设备',
        expand: true,
        List: [{
          zhName: '获取手机网络状态',
          enName: 'getNetworkType',
          url: '../practice/get-network-type/get-network-type'
        }, {
          zhName: '获取手机系统信息',
          enName: 'getSystemInfo',
          url: '../practice/get-system-info/get-system-info'
        }, {
          zhName: '监听重力感应数据',
          enName: 'onAccelerometerChange',
          url: '../practice/on-accelerometer-change/on-accelerometer-change'
        }, {
          zhName: '监听罗盘数据',
          enName: 'onCompassChange',
          url: '../practice/on-compass-change/on-compass-change'
        }]
      }, {
        name: '网络',
        expand: true,
        List: [{
          zhName: '发起一个请求',
          enName: 'request',
          url: '../practice/request/request'
        }, {
          zhName: 'WebSocket',
          enName: 'WebSocket',
          url: '../practice/web-socket/web-socket'
        }, {
          zhName: '上传文件',
          enName: 'Upload File',
          url: '../practice/upload-file/upload-file'
        }, {
          zhName: '下载文件',
          enName: 'Download File',
          url: '../practice/download-file/download-file'
        }]
      }, {
        name: '媒体',
        expand: true,
        List: [{
          zhName: '图片',
          enName: 'chooseImage/previewImage',
          url: '../practice/image/image'
        }, {
          zhName: '录音',
          enName: 'start/stopRecord, play/pause/stopVoice',
          url: '../practice/voice/voice'
        }, {
          zhName: '背景音频',
          enName: 'play/pause/stopAudio',
          url: '../practice/background-audio/background-audio'
        }, {
          zhName: '文件',
          enName: 'saveFile',
          url: '../practice/file/file'
        }, {
          zhName: '视频',
          enName: 'video',
          url: '../practice/video/video'
        }]
      }, {
        name: '位置',
        expand: true,
        List: [{
          zhName: '获取当前位置',
          enName: 'getLocation',
          url: '../practice/get-location/get-location'
        }, {
          zhName: '使用原生地图查看位置',
          enName: 'openLocation',
          url: '../practice/open-location/open-location'
        }]
      }, 
      {
        name: '数据',
        expand: true,
        url: '../practice/storage/storage'
      }]
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload () {

  },

  // onPageScroll(object){

  // },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  // onPullDownRefresh () {

  // },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom () {

  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage (res:any) {
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
      title: '自定义转发内容',
      path: '/page/my?id=123'
    }
  },
  tapMenuItem(item:any) {
    // console.log(item.index)
    // console.log(item.pagePath)
    // console.log(item.text)
    var menuItem = this.data.menuList[parseInt(item.currentTarget.id)] 
    if (menuItem.url) {
      wx.navigateTo({ url: menuItem.url })
    } else {
      var changeData: { [key:string]: any; } = {};
      var opened = menuItem.expand
      var index = parseInt(item.currentTarget.id)
      // 展开操作
      if (opened === false) {
        var openedIndex = -1
        this.data.menuList.forEach(function (menu: any, i: number) {
          if (menu.opened === true) {
            openedIndex = i
          }
        })
        if (openedIndex > -1) {
          changeData['menuList[' + openedIndex + '].opened'] = false
        }
      }
      changeData['menuList[' + index + '].opened'] = !opened
      // this.setData(changeData)
    }
  }
})
